/*
 *所有关于tb_project_type_template类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*tb_project_type_templateService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MYData.System.IRepositories;
using MYData.Core.EFDbContext;
using System.Collections.Generic;
using MYData.Core.Utilities;
using System.Threading.Tasks;
using MYData.Entity.DomainModels;
using System.Linq;

namespace MYData.System.Services
{
    public partial class tb_project_type_templateService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Itb_project_type_templateRepository _repository;//访问数据库
        private readonly VOLContext _context;

        [ActivatorUtilitiesConstructor]
        public tb_project_type_templateService(
            Itb_project_type_templateRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            VOLContext context
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _context = context;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }
        WebResponseContent webResponse = new WebResponseContent();
        /// <summary>
        /// 根据类型Id获取经费模板
        /// </summary>
        /// <param name="TypeId"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> GetTemplateList(string TypeId)
        {
            //获取当前类型下所有的
            var data = from x in _context.Set<tb_project_fundingtemplatesource_relation>().Where(n => n.sourcePartId.Equals(TypeId))
                       join y in _context.Set<Tb_Project_Fundtemplate>().Where(m => m.fundtemplateState.Equals(0) && m.isDelete.Equals(0)) on x.templateId equals y.fundtemplateId
                       select new
                       {
                           y.fundtemplateId,
                           y.fundtemplateName,
                           y.remark,
                           y.fundtemplateFunsRatioName,
                           y.fundtemplateFunsRatio
                       };
            return webResponse.OK("经费模板获取成功", data);
        }

    }
}
